﻿Object.prototype.stringify = function (startSeparator, type) {
    startSeparator = startSeparator || ['{', '}'];
    var str = startSeparator[0], separator = '';

    for (var i in this) {
        if (this[i] instanceof Object && typeof this[i] === 'object') {
            if (this[i] instanceof Array) {
                str += separator + '"' + i + '":' + jsonStringify(this[i], ['[', ']'], 'array');
            }
            else {
                str += separator + '"' + i + '":' + jsonStringify(this[i], null, 'object');
            }
        }
        else if (!(this[i] instanceof Function)) {
            if (type === 'array') {
                str += separator + '"' + this[i] + '"';
            }
            else {
                str += separator + '"' + i + '":"' + this[i] + '"';
            }
        }
        separator = ',';
    }

    return str + startSeparator[1];
};
// ==================================================================================//


$.data = {}
var makePoster = function () {
    //@include ~/Code/mason/poster/make-poster.js
}

var putJettaFormat = function (param) {
    alert(param)
}

var testFn = function(param) {
    alert(param)
}


var makeMR = function(param) {
    // alert(param.kvOption.path.val)
    alert(param.stringify())
    alert('in make btn: ' + $.data.kvPath)
}

var getFilePath = function(key, guideMsg) {
    // var fileType = ($.os.match("Windows")) ? "*.jpg;*.tif;": function (f){
    //     return f instanceof Folder || (f instanceof File && f.fullName.match(/(\.jsx|\.csv)$/i));
    // };
    guideMsg = guideMsg || '选择文件'
    var sourceFile = File.openDialog(guideMsg, undefined, false );
    $.data[key] = sourceFile
}


// ======================utils============================================================//



function jsonStringify (obj, startSeparator, type) {
  startSeparator = startSeparator || ['{','}'];
  var str = startSeparator[0], separator = '';

  for (var i in obj) {
    if (obj[i] instanceof Object && typeof obj[i] === 'object') {
      if (obj[i] instanceof Array) {
        str += separator + '"' + i + '":' + jsonStringify(obj[i], ['[',']'], 'array');
      }
      else {
        str += separator + '"' + i + '":' + jsonStringify(obj[i], null, 'object');
      }
    }
    else if (!(obj[i] instanceof Function)) {
      if (type === 'array') {
        str += separator + '"' + obj[i] + '"';
      }
      else {
        str += separator + '"' + i + '":"' + obj[i] + '"';
      }
    }
    separator = ',';
  }
  return str + startSeparator[1];
}

